//
//  BasicAnimationVC.m
//  CoreAnimation
//
//  Created by LG on 2018/5/17.
//  Copyright © 2018年 iqiyi. All rights reserved.
//

#import "BasicAnimationVC.h"

@interface BasicAnimationVC ()

@property (weak, nonatomic) IBOutlet UIView *viewAnimate;


@end

@implementation BasicAnimationVC

+ (instancetype)obtainvc
{
    UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    BasicAnimationVC *vc = [storyBoard instantiateViewControllerWithIdentifier:@"BasicAnimationVC"];
    
    return vc;
}

- (void)viewDidLoad {
    [super viewDidLoad];
}

- (IBAction)btnClickPosition:(UIButton *)sender
{
    CGPoint viewCenter = self.viewAnimate.center;
    
    CABasicAnimation *basicAni = [[CABasicAnimation alloc]init];
    basicAni.keyPath = @"position";
    basicAni.duration = .5;
    basicAni.fromValue = [NSValue valueWithCGPoint:CGPointMake(viewCenter.x, viewCenter.y)];
    basicAni.toValue = [NSValue valueWithCGPoint:CGPointMake(viewCenter.x, viewCenter.y + 100)];
    
    [self.viewAnimate.layer addAnimation:basicAni forKey:@"a"];
}

- (IBAction)btnClickAlpha:(UIButton *)sender
{
    CABasicAnimation *basicAni = [[CABasicAnimation alloc]init];
    basicAni.keyPath = @"opacity";
    basicAni.duration = .5;
    basicAni.fromValue = @1;
    basicAni.toValue = @0;
    
    [self.viewAnimate.layer addAnimation:basicAni forKey:@"a"];
}

- (IBAction)btnClickScale:(UIButton *)sender
{
    CABasicAnimation *basicAni = [[CABasicAnimation alloc]init];
    basicAni.keyPath = @"transform.scale";
    basicAni.duration = .5;
    basicAni.fromValue = @1; //[NSValue valueWithCGAffineTransform:CGAffineTransformMakeScale(1., 1.)];
    basicAni.toValue = @1.5;//[NSValue valueWithCGAffineTransform:CGAffineTransformMakeScale(1.5, 1.5)];;
    
    [self.viewAnimate.layer addAnimation:basicAni forKey:@"a"];
}

- (IBAction)btnClickRotation:(UIButton *)sender
{
    CABasicAnimation *basicAni = [[CABasicAnimation alloc]init];
    basicAni.keyPath = @"transform.rotation.z";
    basicAni.duration = .5;
    basicAni.fromValue = @1;
    basicAni.toValue = [NSNumber numberWithFloat:M_PI];
    
    [self.viewAnimate.layer addAnimation:basicAni forKey:@"a"];
}

- (IBAction)btnClickBgColor:(UIButton *)sender
{
    CABasicAnimation *basicAni = [[CABasicAnimation alloc]init];
    basicAni.keyPath = @"backgroundColor";
    basicAni.duration = .5;
//    basicAni.fromValue = @1;
    basicAni.toValue = (id)[UIColor blackColor].CGColor;//[NSNumber numberWithFloat:M_PI];
    
    [self.viewAnimate.layer addAnimation:basicAni forKey:@"a"];
}

@end
